package com.markus.basic.设计模式.单例模式;

/**
 * Author:markusZhang
 * Date:Create in 2020/8/24 15:51
 * todo: 懒汉式
 */
public class SingleTon1 {
    private static SingleTon1 instance;

    /**
     * 将构造器设为私有
     */
    private SingleTon1(){}

    /**
     * 线程不安全
     */
    public static SingleTon1 getInstance(){
        if (instance == null){
            instance = new SingleTon1();
        }
        return instance;
    }

    /**
     * 线程安全
     */
    public static synchronized SingleTon1 getInstanceWithLock(){
        if (instance == null){
            instance = new SingleTon1();
        }
        return instance;
    }

}
